package fudan.se.project.service.infrastructure.func.account.user;

import fudan.se.project.domain.User;
import fudan.se.project.domain.conference.Conference;
import fudan.se.project.domain.conference.Topic;
import fudan.se.project.domain.conference.role.Chair;
import fudan.se.project.service.infrastructure.entity.conference.ConferenceService;
import fudan.se.project.service.infrastructure.entity.conference.TopicService;
import fudan.se.project.service.infrastructure.entity.conference.role.ChairService;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.HashSet;

@Slf4j
@Service
@RequiredArgsConstructor
public class ConferenceApplyService {

    @NonNull
    private final TopicService topicService;
    @NonNull
    private final ConferenceService conferenceService;
    @NonNull
    private final ChairService chairService;


    public boolean process(User userChair, Conference conference, Collection<String> topicStrings) {
        conference = conferenceService.save(conference);

        Collection<Topic> topics = new HashSet<>();
        for (String topicString : topicStrings) {
            Topic topic = new Topic(topicString, conference);
            topics.add(topic);
        }

        topicService.saveAll(topics);

        Chair chair = new Chair(userChair, conference);

        chairService.save(chair);

        return true;
    }
}
